define(['jquery', 'knockout', 'eventbus', 'dataservice'], function ($, ko, eventbus, ds) {
	return function () {
		let errorStatus = ko.observable("");
		// Click callback for the registration button.
		let onRegisterClick = function () {
			// TODO: do we really need jQuery for this? other options with kockout?
			let regData = {
				name: $("#name").val(),
				email: $("#email").val(),
				password: $("#password").val()
			}
			if (regData.password.length >= 8) {
				errorStatus("");
				// Send the account details to the backend.
				ds.postNewAccount(function () {
					// Notify the rest of the components.
					eventbus.publish("changeComponentEvent", "login");
				}, regData);
			} else {
				errorStatus("Password must be minimum 8 characters long");
			}
		}

		// Expose what the UI needs.
		return {
			title: 'Registration',
			onRegisterClick,
			errorStatus,
		}
	}
});